module client.GateServerClient;

import std.stdio;
import msgtrans;
import hunt.logging;

class GateServerClient {

  private __gshared GateServerClient _instance;

  private TransportSession[ulong] _forwardClientMap;

  private uint _size = 0;

  static public GateServerClient getInstance()
  {
    if (_instance is null)
    {
      _instance = new GateServerClient();
    }
    return _instance;
  }

  public void deleForwardClient(ulong id)
  {
    synchronized(this){
      if (id in _forwardClientMap)
      {
        _forwardClientMap.remove(id);
        _size -= 1;
      }
    }
  }

  public void addForwardClient(TransportContext client,ulong id)
  {
    synchronized(this){
      if (id in _forwardClientMap)
      {
        logErrorf("gateServer id(%d) have exist!", id);
      }

      _forwardClientMap[id] = client.session();
      _size += 1;
    }

  }

  public TransportSession[ulong] getAllClient()
  {
    TransportSession[ulong] rt ;
    synchronized(this){
        rt = _forwardClientMap;
    }
    return rt;
  }
}

